package com.example.administrator.printoutindemo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.bean.ChukuandMudiBean;
import com.example.administrator.printoutindemo.bean.ShenHeRenBean;
import com.example.administrator.printoutindemo.http.SPUtil;

import java.util.List;

/**
 * Created by noc on 2018/10/24.
 */

public class ChukuandMudiAdapter extends BaseAdapter {

    Context context;
    List<ChukuandMudiBean> list;
    LayoutInflater inflater;

    public ChukuandMudiAdapter(Context context, List<ChukuandMudiBean> list) {
        this.context = context;
        this.list = list;
        this.inflater=LayoutInflater.from(context);
    }

    public LayoutInflater getInflater() {
        return inflater;
    }

    public void setInflater(LayoutInflater inflater) {
        this.inflater = inflater;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder=null;
        if (view==null){
            view=getInflater().inflate(R.layout.shritem,null);
            holder=new ViewHolder();
            holder.tv_shr=view.findViewById(R.id.tv_shr);
            holder.ll_item=view.findViewById(R.id.ll_item);
            view.setTag(holder);
        }else {
            holder= (ViewHolder) view.getTag();
        }
      if (list.get(i).getProjectname()!=null){
          holder.tv_shr.setText(list.get(i).getProjectname());
      }
        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SPUtil.putString(context,"projectname",list.get(i).getProjectname());
                SPUtil.putString(context,"proid",list.get(i).getProid());
                if (Activity.class.isInstance(context)){
                    Activity activity= (Activity) context;
                    activity.finish();
                }
            }
        });
        return view;
    }
    class ViewHolder{
        TextView tv_shr;
        LinearLayout ll_item;
    }
    public void addAll(List<ChukuandMudiBean> cangku){
        list.addAll(cangku);
        notifyDataSetChanged();
    }
}
